/*
 * QFontManager.cpp
 *
 *  Created on: 2009-9-9
 *      Author: rockling
 */
#include <EIKENV.H>
#include <W32STD.H>

#include "QFontManager.h"
//#include "QInstance.h"

_LIT(KFontName, "Sans MT 936_S60");

CQFontManager::CQFontManager()
	{
	}

CQFontManager::~CQFontManager()
	{
	}

EXPORT_C CQFont* CQFontManager::GetFont(TFontSpec aSpec)
	{	
	CFont* pFont;
	CEikonEnv::Static()->ScreenDevice()->GetNearestFontInTwips(pFont,aSpec);
	return new CQFont(pFont,1);
	}

EXPORT_C CQFont* CQFontManager::GetFont(TFontSpec aSpec,QINT aType)
	{
	CFont* pFont;
	CEikonEnv::Static()->ScreenDevice()->GetNearestFontInTwips(pFont,aSpec);
	return new CQFont(pFont,aType);
	}

EXPORT_C CQFont* CQFontManager::GetFont(QINT height,QINT aGlyphBitmap)
{
	TGlyphBitmapType glyphBitmap = (TGlyphBitmapType)aGlyphBitmap;
#ifdef __SERIES60_3X__
	TInt twips = CEikonEnv::Static()->ScreenDevice()->VerticalPixelsToTwips(height);
	TFontSpec spec(KFontName, twips);
	spec.iFontStyle.SetBitmapType(glyphBitmap);
	return GetFont(spec);
#else
	if (height > FONT_MEDIUM)
	{
		return CEikonEnv::Static()->TitleFont();
	}
	else
	{
		return CEikonEnv::Static()->DenseFont();
	}
#endif
}
static int nDebug = 0;
EXPORT_C CQFont* CQFontManager::GetBoldFont(QINT height)
{
#ifdef __SERIES60_3X__
	TInt twips = CEikonEnv::Static()->ScreenDevice()->VerticalPixelsToTwips(height);
	TFontSpec spec(KFontName, twips);
	spec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
	if(nDebug)
	{
		TGlyphBitmapType glyphBitmap = (TGlyphBitmapType)0;
		spec.iFontStyle.SetBitmapType(glyphBitmap);		
	}
	return GetFont(spec);
#else
	if (height > FONT_MEDIUM)
	{
		return CEikonEnv::Static()->TitleFont();
	}
	else
	{
		return CEikonEnv::Static()->DenseFont();
	}
#endif
}

EXPORT_C CQFont* CQFontManager::GetFont(CFont* aFont)
{
	if(!aFont)
		return NULL;

	return new CQFont(aFont,1);
}

EXPORT_C CQFont* CQFontManager::GetFont(QINT height)
{
#ifdef __SERIES60_3X__
	TInt twips = CEikonEnv::Static()->ScreenDevice()->VerticalPixelsToTwips(height);
	TFontSpec spec(KFontName, twips);
	
	//spec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
	//spec.iFontStyle.SetEffects(FontEffect::ESoftEdge,ETrue);
	
	/*TOpenFontSpec openSpec;
	openSpec.SetName( KFontName );
	openSpec.SetHeight(  height  ); 
	openSpec.SetBitmapType( EAntiAliasedGlyphBitmap );
	openSpec.SetBold( EFalse );
	openSpec.SetItalic( EFalse );
	openSpec.SetBitmapType( EAntiAliasedGlyphBitmap );*/

	return GetFont(spec);
#else
	if (height > FONT_MEDIUM)
	{
		return CEikonEnv::Static()->TitleFont();
	}
	else
	{
		return CEikonEnv::Static()->DenseFont();
	}
#endif
}

EXPORT_C QINT32 CQFontManager::GetHeightInTwips(QINT height)
{
	return CEikonEnv::Static()->ScreenDevice()->VerticalPixelsToTwips(height);
}

EXPORT_C void CQFontManager::GetAvailableFontsL(CDesCArray& aFontNameList,TInt aFonts)
{
	CWsScreenDevice* screenDevice = CEikonEnv::Static()->ScreenDevice();

	/*CFont* font = (CFont*)CEikonEnv::Static()->AnnotationFont();
	TFontSpec spec = font->FontSpecInTwips();
	aFontNameList.AppendL(spec.iTypeface.iName);

	font = (CFont*)CEikonEnv::Static()->TitleFont();
	TFontSpec spec1 = font->FontSpecInTwips();
	aFontNameList.AppendL(spec1.iTypeface.iName);

	font = (CFont*)CEikonEnv::Static()->LegendFont();
	TFontSpec spec2 = font->FontSpecInTwips();
	aFontNameList.AppendL(spec2.iTypeface.iName);

	font = (CFont*)CEikonEnv::Static()->SymbolFont();
	TFontSpec spec3 = font->FontSpecInTwips();
	aFontNameList.AppendL(spec3.iTypeface.iName);

	font = (CFont*)CEikonEnv::Static()->DenseFont();
	TFontSpec spec4 = font->FontSpecInTwips();
	aFontNameList.AppendL(spec4.iTypeface.iName);
	
	font = (CFont*)CEikonEnv::Static()->NormalFont();
	TFontSpec spec5 = font->FontSpecInTwips();
	aFontNameList.AppendL(spec5.iTypeface.iName);*/
	/*TInt count = screenDevice->NumTypefaces();
	for(TInt i=0;i<count;i++)
	{
		TTypefaceSupport support;
		screenDevice->TypefaceSupport(support,i);
		aFontNameList.AppendL(support.iTypeface.iName);
	}*/
	FontUtils::GetAvailableFontsL(*screenDevice,aFontNameList,aFonts);
}
